#include <bits/stdc++.h>
using namespace std;

const int N = 3e5+5;
typedef long long LL;
int n, m, a, b;

vector<int> G[N];

int siz[N];
bool vis[N];

int root;
void dfs(int u, int fa) {
    // printf("dfs %d %d\n", u, fa);
    siz[u] = vis[u] = 1;
    if (!~fa) siz[u] = 0;
    if (u == b) {
        siz[u] = -1;
        return;
    }
    for (int v : G[u]) {
        if (vis[v]) {
            if (siz[v] == -1 && fa != -1) {
                siz[u] = -1;
                return;
            } else continue;
        }
        dfs(v, u);
        if (siz[v] == -1) {
            if (~fa) {
                siz[u] = -1;
                return;
            }
        } else
            siz[u] += siz[v];
    }
}

void dbg() {
    for (int i=1; i<=n; ++i) {
        printf("i=%d, siz=%d\n", i, siz[i]);
    }
}

int main(int argc, char const *argv[])
{
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d%d%d", &n, &m, &a, &b);
        for (int i=0; i<=n; ++i) {
            G[i].clear();
            siz[i] = vis[i] = 0;
        }
        for (int i=0; i<m; ++i) {
            int u, v; scanf("%d%d", &u, &v);
            G[u].push_back(v);
            G[v].push_back(u);
        }
        dfs(a, -1);
        // dbg();
        LL h1 = siz[a];
        swap(a, b);
        memset(siz, 0, sizeof(int) * (n+1));
        memset(vis, 0, sizeof(bool) * (n + 1));
        dfs(a, -1);
        // dbg();
        LL h2 = siz[a];
        LL ans = h1 * h2;
        printf("%lld\n", ans);

    }
    
    return 0;
}
